package com.fare.fdc.action;

import java.util.List;
import java.util.Locale;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.fare.taluo.BaseFdcAction;
import com.fare.taluo.application.analyse.AheadBuyTicketApplication;
import com.fare.taluo.application.plane.channel.SourceApplication;
import com.fare.taluo.auth.security.ContextLoginUser;
import com.fare.taluo.util.I18nUtil;
import com.fare.taluo.vo.core.QueryVo;
import com.fare.taluo.vo.core.SourceEntityVO;

/**
 * 提前购票
 * @author spring.华 
 */
@Controller("aheadBuyTicketAction")
@Scope("prototype")
public class AheadBuyTicketAction extends BaseFdcAction{
	
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -6975564304474594618L;
	
	@Resource(name="sourceApplication")
	private SourceApplication sourceApplication;
	@Resource(name="aheadBuyTicketApplicationImpl")
	private AheadBuyTicketApplication aheadBuyTicketApplication;
	private QueryVo  vo;
	private String fromCity;
	private String toCity;
	private String fromCityCode;
	private String toCityCode;
	private List<SourceEntityVO> crawlCompanys;//所有的当前处于抓取状态的公司
	private List<SourceEntityVO> crawlChannels;//所有的当前处于抓取状态的渠道
	private SourceEntityVO myCompanyOrChannel;//指当前用户所在的公司或者渠道
	private String[] compareDataSource;//比较的数据来源，见需求文档（1个官网+多个渠道）
	private String language;
	
	public String toView() throws Exception{
		returnPageURL = "/fare/fdc/tqgpyjfx.jsp";
		this.crawlCompanys=sourceApplication.findCrawlAirCompanys();
		this.crawlChannels=sourceApplication.findCrawlChannel();
		request.setAttribute("myCompanyOrChannel", ContextLoginUser.getLoginUser().getSourceKey());
		Locale locale = super.getLocale();
		I18nUtil.sourceConvert2I18N(crawlCompanys, locale);
		I18nUtil.sourceConvert2I18N(crawlChannels, locale);
		language=locale.toString();
		if(!language.equalsIgnoreCase("zh_CN") && !language.equalsIgnoreCase("en_US")){
			language="other";
		}
		return "dispatcher";
	}
	
	public void searchView() throws Exception{
		Locale locale = super.getLocale();
		String xml= aheadBuyTicketApplication.getFusionChartsXMLStr(fromCityCode,toCityCode,
				vo.getFlightNo(), vo.getDepTime(), compareDataSource,locale);
		super.toJSONOut(xml);
	}

	public QueryVo getVo() {
		return vo;
	}

	public void setVo(QueryVo vo) {
		this.vo = vo;
	}

	public SourceApplication getSourceApplication() {
		return sourceApplication;
	}

	public void setSourceApplication(SourceApplication sourceApplication) {
		this.sourceApplication = sourceApplication;
	}

	public List<SourceEntityVO> getCrawlCompanys() {
		return crawlCompanys;
	}

	public void setCrawlCompanys(List<SourceEntityVO> crawlCompanys) {
		this.crawlCompanys = crawlCompanys;
	}

	public List<SourceEntityVO> getCrawlChannels() {
		return crawlChannels;
	}

	public void setCrawlChannels(List<SourceEntityVO> crawlChannels) {
		this.crawlChannels = crawlChannels;
	}

	
	public SourceEntityVO getMyCompanyOrChannel() {
		return myCompanyOrChannel;
	}

	public void setMyCompanyOrChannel(SourceEntityVO myCompanyOrChannel) {
		this.myCompanyOrChannel = myCompanyOrChannel;
	}

	public AheadBuyTicketApplication getAheadBuyTicketApplication() {
		return aheadBuyTicketApplication;
	}

	public void setAheadBuyTicketApplication(
			AheadBuyTicketApplication aheadBuyTicketApplication) {
		this.aheadBuyTicketApplication = aheadBuyTicketApplication;
	}

	public String[] getCompareDataSource() {
		return compareDataSource;
	}

	public void setCompareDataSource(String[] compareDataSource) {
		this.compareDataSource = compareDataSource;
	}

	public String getFromCity() {
		return fromCity;
	}

	public void setFromCity(String fromCity) {
		this.fromCity = fromCity;
	}

	public String getToCity() {
		return toCity;
	}

	public void setToCity(String toCity) {
		this.toCity = toCity;
	}

	public String getFromCityCode() {
		return fromCityCode;
	}

	public void setFromCityCode(String fromCityCode) {
		this.fromCityCode = fromCityCode;
	}

	public String getToCityCode() {
		return toCityCode;
	}

	public void setToCityCode(String toCityCode) {
		this.toCityCode = toCityCode;
	}

	public String getLanguage() {
		return language;
	}

	public void setLanguage(String language) {
		this.language = language;
	}
	
	

	
	
	
}
